def is_prime(num):
    if num <= 1:
        return False
    for i in range(2, int(num*0.5) + 1):
        if num % i == 0:
            return False
    return True

def find_closest_prime(num):
    if is_prime(num):
        return num
    lower_prime = num - 1
    upper_prime = num + 1
    while True:
        if is_prime(lower_prime):
            return lower_prime
        if is_prime(upper_prime):
            return upper_prime
        lower_prime -= 1
        upper_prime += 1

words_to_digits = {
    "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
    "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
}

input_words = input().split()

if len(input_words) != 3:
    print("Wrong input")
else:
    try:
        number = (
                words_to_digits[input_words[0]] * 100 +
                words_to_digits[input_words[1]] * 10 +
                words_to_digits[input_words[2]]
        )
        print(find_closest_prime(number))
    except KeyError:\
    print("Wrong input")
